
package com.v1.video.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.v1.video.R;
import com.v1.video.option.db.SearchKeyInfo;

public class SearchKeyAdapter extends BaseAdapter {
    private List<SearchKeyInfo> infos;

    public List<SearchKeyInfo> getInfos() {
        return infos;
    }

    public void setInfos(List<SearchKeyInfo> infos) {
        this.infos = infos;
    }

    private Context context;

    public SearchKeyAdapter(Context context) {
        this.context = context;
    }

    public SearchKeyAdapter(Context context, List<SearchKeyInfo> infos) {
        this(context);
        this.infos = infos;
    }
    
    public void updata(List<SearchKeyInfo> infos){
        this.infos = infos;
        this.notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView != null)
            holder = (ViewHolder) convertView.getTag();
        else {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_search_key, null);
            holder.key = (TextView) convertView.findViewById(R.id.item_search_key_con);
            holder.line1 = (View) convertView.findViewById(R.id.item_search_key_line1);
            convertView.setTag(holder);
        }
        if(position == 0){
        	holder.line1.setVisibility(View.VISIBLE);
        }else{
        	holder.line1.setVisibility(View.GONE);
        }
        final SearchKeyInfo info = infos.get(position);
        holder.key.setText(info.key);        

        return convertView;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Object getItem(int position) {
        return infos.get(position);
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    static class ViewHolder {        
        TextView key;        
        View line1;
    }
}
